package com.yunji.system.service;

import com.yunji.common.convert.NoticeConvert;
import com.yunji.common.model.domain.NoticeUserDO;
import com.yunji.common.model.dto.LoginInfo;
import com.yunji.common.model.params.NoticeParams;
import com.yunji.common.model.vo.NoticeVO;
import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.system.context.SystemContext;
import com.yunji.system.dao.INoticeUserDao;
import javafx.util.Pair;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class NoticeUserService {

    @Resource
    private INoticeUserDao noticeUserDao;

    public void saveBatch(ArrayList<NoticeUserDO> list) {
        noticeUserDao.saveBatch(list);
    }

    public Integer countUnread() {
        LoginInfo user = SystemContext.getUser();
        return noticeUserDao.countUnread(new Pair<>(user.getUserType(),user.getUserId()));
    }

    public void allRead() {
        LoginInfo user = SystemContext.getUser();
        noticeUserDao.allRead(new Pair<>(user.getUserType(),user.getUserId()));
    }

    public List<NoticeVO> pageList(NoticeParams params) {
        LoginInfo user = SystemContext.getUser();
        BeanUtils.clone(user,params);
        List<NoticeVO> list = noticeUserDao.getPageList(params);
        NoticeConvert.contentToMap(list);
        return list;
    }
}
